home *** CD-ROM | disk | FTP | other *** search
/ Freelog 125 / Freelog_MarsAvril2015_No125.iso / Musique / Quod Libet / quodlibet-3.3.0-portable.exe / quodlibet-3.3.0-portable / data / bin / ctypes / _endian.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2014-12-31  |  2KB  |  58 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.7)
  3.  
  4. import sys
  5. from ctypes import *
  6. _array_type = type(Array)
  7.  
  8. def _other_endian(typ):
  9.     """Return the type with the 'other' byte order.  Simple types like
  10.     c_int and so on already have __ctype_be__ and __ctype_le__
  11.     attributes which contain the types, for more complicated types
  12.     arrays and structures are supported.
  13.     """
  14.     if hasattr(typ, _OTHER_ENDIAN):
  15.         return getattr(typ, _OTHER_ENDIAN)
  16.     if None(typ, _array_type):
  17.         return _other_endian(typ._type_) * typ._length_
  18.     if None(typ, Structure):
  19.         return typ
  20.     raise None('This type does not support other endian: %s' % typ)
  21.  
  22.  
  23. class _swapped_meta(type(Structure)):
  24.     
  25.     def __setattr__(self, attrname, value):
  26.         if attrname == '_fields_':
  27.             fields = []
  28.             for desc in value:
  29.                 name = desc[0]
  30.                 typ = desc[1]
  31.                 rest = desc[2:]
  32.                 fields.append((name, _other_endian(typ)) + rest)
  33.             
  34.             value = fields
  35.         super(_swapped_meta, self).__setattr__(attrname, value)
  36.  
  37.  
  38. if sys.byteorder == 'little':
  39.     _OTHER_ENDIAN = '__ctype_be__'
  40.     LittleEndianStructure = Structure
  41.     
  42.     class BigEndianStructure(Structure):
  43.         '''Structure with big endian byte order'''
  44.         __metaclass__ = _swapped_meta
  45.         _swappedbytes_ = None
  46.  
  47. elif sys.byteorder == 'big':
  48.     _OTHER_ENDIAN = '__ctype_le__'
  49.     BigEndianStructure = Structure
  50.     
  51.     class LittleEndianStructure(Structure):
  52.         '''Structure with little endian byte order'''
  53.         __metaclass__ = _swapped_meta
  54.         _swappedbytes_ = None
  55.  
  56. else:
  57.     raise RuntimeError('Invalid byteorder')
  58.